Inside Macintosh: QuickTime Components
| Previous | Chapter contents | Chapter top | Section top | Next |
To export data to a PICS file, your component must
Listing 4 provides an implementation of these tasks in a movie export component. The ExportPICSToFile function performs the export operation by opening the resource fork of the PICS file and cycling through the movie time segment, adding a frame to the PICS file.
Listing 4 Exporting a frame of movie data to a PICS file
pascal ComponentResult ExportPICSToFile (ExportPICSGlobals store,
const FSSpec *theFile,
Movie m,
Track onlyThisTrack,
TimeValue startTime,
TimeValue duration)
{
OSErr err = noErr;
short resRef = 0;
short saveResRef = CurResFile();
short resID = 128;
PicHandle thePict = nil;
/* open the resource fork of the PICS file
(the caller is responsible for creating the file) */
resRef = FSpOpenResFile (theFile, fsRdWrPerm);
if (err = ResError()) goto bail;
UseResFile(resRef);
/* cycle through the movie time segment you were given */
while (startTime < duration) {
Byte c = 0;
if (onlyThisTrack)
thePict = GetTrackPict (onlyThisTrack, startTime);
else
thePict = GetMoviePict(m, startTime);
if (!thePict) continue;
/* add a frame to the PICS file */
AddResource ((Handle)thePict, 'PICT', resID++, &c);
err = ResError();
WriteResource ((Handle)thePict);
DetachResource ((Handle)thePict);
KillPicture (thePict);
thePict = nil;
if (err) break;
/* find the time of the next frame */
do {
TimeValue nextTime;
if (onlyThisTrack)
GetTrackNextInterestingTime (onlyThisTrack,
nextTimeMediaSample, startTime,
kFix1, &nextTime, nil);
else {
OSType mediaType = VisualMediaCharacteristic;
GetMovieNextInterestingTime (m, nextTimeMediaSample,
1, &mediaType,
startTime, kFix1,
&nextTime, nil);
}
if (GetMoviesError ()) goto bail;
if (nextTime != startTime) {
startTime = nextTime;
break;
}
} while (++startTime < duration);
}
bail:
if (thePict) KillPicture (thePict);
if (resRef) CloseResFile (resRef);
UseResFile (saveResRef);
return err;
}
| Previous | Chapter contents | Chapter top | Section top | Next |